Replace Text UserScript
code:format
(before) => (after)
(before) => (after)
:
(before) => (after)
(text)
(text)
:
(text)
code:sample1
/a|\s/g=>b
ab a b a aba b a ba bb
code:sample2
/\s/g => fuga
hoge hoge hoge
code: script.js
const replaceText = text => {
const splitPos = text.indexOf('\n\n')
const commands = text.substr(0, splitPos).split('\n').map(command => {
return { before, after }
})
let lines = text.substr(splitPos + 2).split('\n')
for (const { before, after } of commands) {
const match = before.match(new RegExp('^/(.*?)/(gimy*)$')) const reg = match ? new RegExp(match1, match2) : before lines = lines.map(line => line.replace(reg, after.replace(/\\n/g, '\n')))
}
return lines.join('\n')
}
scrapbox.PopupMenu.addButton({
title: 'replace',
onClick: replaceText
})